<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="mvc.domain.Student"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Student</title>
</head>
<body>
	<div style="color: red"><%=request.getAttribute("errorMessage") == null ? "" : request.getAttribute("errorMessage")%></div>
	<%
		String id = null;
		String oldName = null;
		String newName = null;
		String age = null;
		String gender = null;
		String birthday = null;

		Student student = (Student) request.getAttribute("student");
		if (student != null) {
			id = String.valueOf(student.getId());
			oldName = student.getName();
			newName = oldName;
			age = String.valueOf(student.getAge());
			gender = student.getGender();
			birthday = new SimpleDateFormat("yyyy-MM-dd").format(student.getBirthday());
		} else {
			id = request.getParameter("id");
			oldName = request.getParameter("oldName");
			newName = oldName;
			age = request.getParameter("age");
			gender = request.getParameter("gender");
			birthday = request.getParameter("birthday");
		}
	%>
	<form action="update.do" method="post">
		<table>
			<tr>
				<td>Name:</td>
				<td><input type="text" name="name" value="<%=oldName%>" /></td>
			</tr>
			<tr>
				<td>Age:</td>
				<td><input type="text" name="age" value="<%=age%>" /></td>
			</tr>
			<tr>
				<td>Gender:</td>
				<td><input type="text" name="gender" value="<%=gender%>" /></td>
			</tr>
			<tr>
				<td>Birthday:</td>
				<td><input type="text" name="birthday" value="<%=birthday%>" /></td>
			</tr>
		</table>
		<input type="hidden" name="oldName" value="<%=oldName%>" /> <input
			type="hidden" name="id" value="<%=id%>" /> <input type="submit"
			value="Update" />
	</form>
</body>
</html>